<?php
/**
 * ===== groups
 * root = 1
 * administrator = 3
 * moderator = 4
 * editor = 5
 * ====/ groups
 */
$currentUsr = $session->read('MyApp_Users.InfoSettings.authCurrentUser');
?>

<div class="users index">
<h2><?php echo 'Система - потребители'; ?></h2>
<p>
<?php
echo $paginator->counter(array(
'format' => 'Страницa %page% от %pages%, показваща %current% записа от %count% общо, започваща от запис %start%, свършваща на запис %end%'
));
?></p>
<table cellpadding="0" cellspacing="0">
<tr>
	<th>
	<?php
		echo $paginator->sort(
			'ID',
			'id',
			array('url' => array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'index'))
		);
	?>
	</th>
	<th>
	<?php
		echo $paginator->sort(
			'Потребителското име',
			'username',
			array('url' => array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'index'))
		);
	?>
	</th>
	<th>
	<?php
		echo $paginator->sort(
			'Група',
			'group_id',
			array('url' => array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'index'))
		);
	?>
	</th>
	<?php
	if(Configure::read('MyApp_Users.Settings.accountActivation')) {
		echo '<th>'."\n";
			echo $paginator->sort(
				'Активиран',
				'is_active',
				array('url' => array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'index'))
			);
		echo '</th>'."\n";
	}
	?>
	<th class="actions"><?php echo 'Действия'; ?></th>
</tr>
<?php
$i = 0;
foreach ($users as $user) {
	$class = null;
	if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	}
?>
	<tr<?php echo $class;?>>
		<td>
			<?php echo $user['User']['id']; ?>
		</td>
		<td>
			<?php echo $user['User']['username']; ?>
		</td>
		<td>
			<?php echo $this->Html->link($user['Group']['title'], array('admin' => true, 'plugin' => null, 'controller' => 'groups', 'action' => 'view', $user['Group']['id'])); ?>
		</td>
		<?php
		if(Configure::read('MyApp_Users.Settings.accountActivation')) {
			echo '<td>'."\n";
				if($user['User']['is_active']) {
					echo '<span style="color: green">'.'да'.'</span>';
				} else {
					echo '<span style="color: red">'.'не'.'</span>';
				}
			echo '</td>'."\n";
		}  ?>

			<td class="actions">
			<?php echo $this->Html->link('Преглед', array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'view', $user['User']['id'])); ?>
			<?php echo $this->Html->link('Редактиране', array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'edit', $user['User']['id'])); ?>
			<?php echo $this->Html->link('Изтриване', array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'delete', $user['User']['id']), null, sprintf('Сигурни ли сте, че искате да изтриете # %s?', $user['User']['id'])); ?>
			<?php 
				if($user['User']['is_active'] == 1){
					echo $this->Html->link('Block', array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'view', $user['User']['id'], 'block'));
				} else {
					echo $this->Html->link('Unblock', array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'view', $user['User']['id'], 'unblock'));
				}
			 ?>
		</td>	
	</tr>
<?php } ?>
</table>
</div>
<div class="paging">
	<?php echo $paginator->prev('<< '.'previous', array('url' => array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'index')), null, array('class'=>'disabled'));?>
 | 	<?php echo $paginator->numbers(array('url' => array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'index')));?>
	<?php echo $paginator->next('next'.' >>', array('url' => array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'index')), null, array('class'=>'disabled'));?>
</div>
<!--
<div class="actions">
	<ul>
		<li>
		<?php
		if($currentUsr["User"]["group_id"] == 1) {
			echo $this->Html->link('Добави потребител', array('admin' => true, 'plugin' => null, 'controller' => 'users', 'action' => 'add'));
		}
		?>
		</li>
	</ul>
</div> -->
